package Meta

import (
	"db2s/ETL"
	"db2s/global"
	"db2s/parDef"
	"db2s/ref"
)

func (ma Meta) tableEr(drive string) (ter TableEr, err error) {
	if ter, err = NewMetaTable(drive); err != nil {
		err = ref.ErrAddPrintf("tableEr", err)
		return
	}
	return
}
func (ma Meta) tableName() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Name(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.StringGarth))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableName", err)
		return
	}
	return
}
func (ma Meta) tableExistence() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Existence(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], SeqNameEq, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableExistence", err)
		return
	}
	return
}
func (ma Meta) tableDrop() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Drop(parDef.CtxBackground(parDef.GeneralWriteMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableDrop", err)
		return
	}
	return
}
func (ma Meta) tableRename() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Rename(parDef.CtxBackground(parDef.GeneralWriteMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableRename", err)
		return
	}
	return
}
func (ma Meta) tableRecover() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Recover(parDef.CtxBackground(parDef.GeneralWriteMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableRecover", err)
		return
	}
	return
}
func (ma Meta) tableTruncate() (meta any, err error) {
	var ter TableEr
	var event = "[tableTruncate]"
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Truncate(parDef.CtxBackground(parDef.GeneralWriteMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf(event, err)
		return
	}
	return
}
func (ma Meta) tableAnalyze() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Analyze(parDef.CtxBackground(parDef.GeneralWriteMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableAnalyze", err)
		return
	}
	return
}

func (ma Meta) partNameToShardName() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.PartNameToShardName(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("PartNameToShardName", err)
		return
	}
	return
}
func (ma Meta) execDDL() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.ExecDDL(parDef.CtxBackground(parDef.GeneralWriteMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("execDDL", err)
		return
	}
	return
}
func (ma Meta) tableComment() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Comment(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableComment", err)
		return
	}
	return
}
func (ma Meta) tableCharacter() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Character(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableCharacter", err)
		return
	}
	return
}
func (ma Meta) tableCollation() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Collation(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.String))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableCollation", err)
		return
	}
	return
}
func (ma Meta) tableConstraints() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.Constraints(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.SMap))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableConstraints", err)
		return
	}
	return
}
func (ma Meta) tableCreateGeneral() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.CreateGeneral(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableCreateGeneral", err)
		return
	}
	return
}
func (ma Meta) tableCreatePrint() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.CreatePrint(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableCreatePrint", err)
		return
	}
	return
}
func (ma Meta) tableAlterGeneral() (meta any, err error) {
	var ter TableEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.tableEr(v); err != nil {
			return
		}
		if result, err = ter.AlterGeneral(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ""))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("tableAlterGeneral", err)
		return
	}
	return
}
func (ma Meta) GetTableCommentMetaST() (meta any, err error) {
	return ma.tableComment()
}
func (ma Meta) GetTableCharacterMetaST() (meta any, err error) {
	return ma.tableCharacter()
}
func (ma Meta) GetTableCollationMetaST() (meta any, err error) {
	return ma.tableCollation()
}
func (ma Meta) GettableConstraintsST() (meta any, err error) {
	return ma.tableConstraints()
}
func (ma Meta) DDLCreateTableGeneralST() (meta any, err error) {
	return ma.tableCreateGeneral()
}
func (ma Meta) DDLCreateTablePrintST() (meta any, err error) {
	return ma.tableCreatePrint()
}
func (ma Meta) DDLAlterTableGeneralST() (meta any, err error) {
	return ma.tableAlterGeneral()
}
func (ma Meta) GetPartNameToShardNameST() (meta any, err error) {
	return ma.partNameToShardName()
}
